{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Sum of Digits in the Minimum Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: sumOfDigits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #最小元素各数位之和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个正整数的数组 <code>A</code>。</p>\n",
    "\n",
    "<p>然后计算 <code>S</code>，使其等于数组 <code>A</code> 当中最小的那个元素各个数位上数字之和。</p>\n",
    "\n",
    "<p>最后，假如 <code>S</code> 所得计算结果是 <strong>奇数 </strong>，返回 0 ；否则请返回 1。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>[34,23,1,24,75,33,54,8]\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>\n",
    "最小元素为 1 ，该元素各个数位上的数字之和 S = 1 ，是奇数所以答案为 0 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>[99,77,33,66,55]\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>\n",
    "最小元素为 33 ，该元素各个数位上的数字之和 S = 3 + 3 = 6 ，是偶数所以答案为 1 。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= A.length <= 100</code></li>\n",
    "\t<li><code>1 <= A[i] <= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [sum-of-digits-in-the-minimum-number](https://leetcode.cn/problems/sum-of-digits-in-the-minimum-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [sum-of-digits-in-the-minimum-number](https://leetcode.cn/problems/sum-of-digits-in-the-minimum-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[34,23,1,24,75,33,54,8]', '[99,77,33,66,55]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        k=min(nums)\n",
    "        s=str(k)\n",
    "        ret=0\n",
    "        for i in s:\n",
    "            ret=ret+int(i)\n",
    "        print(ret)\n",
    "        if ret%2:return 0\n",
    "        return 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def sumOfDigits(self, nums):\n",
    "        nums.sort()\n",
    "        mi=min(nums)\n",
    "        print(mi)\n",
    "        sum=0\n",
    "        while mi>0:\n",
    "            sum+=mi%10\n",
    "            mi//=10\n",
    "        print(sum)\n",
    "        if sum%2==0:\n",
    "            return 1\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        return (sum(int(i) for i in str(min(nums)))+1)%2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        return 0 if sum(int(x) for x in str(min(nums))) % 2 else 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        num = min(nums)\n",
    "        cnt = 0\n",
    "        while num:\n",
    "            cnt += num % 10\n",
    "            num //= 10\n",
    "        return 1 if cnt % 2 == 0 else 0\n",
    "              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        ref = min(nums)\n",
    "        s = 0\n",
    "        while ref > 0:\n",
    "            s += ref % 10\n",
    "            ref //= 10\n",
    "        return 0 if s % 2 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        low = min(nums)\n",
    "        res = sum(int(w) for w in str(low))\n",
    "        return 1 -  res%2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "      minVal = min(nums)\n",
    "      ans = 0\n",
    "      while minVal:\n",
    "        ans += minVal % 10\n",
    "        minVal //= 10\n",
    "      return (ans + 1) % 2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        return 1 - sum([int(x) for x in str(min(nums))])%2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        minNum=int(min(nums))\n",
    "        print(minNum)\n",
    "        amount=0\n",
    "        s=0\n",
    "        while minNum>0:\n",
    "            s+=minNum%10\n",
    "            minNum=minNum//10\n",
    "        if s%2==1:\n",
    "            return 0\n",
    "        else:\n",
    "            return 1\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        #return 1 if len(str(min(nums))) % 2 == 0 else 0\n",
    "\n",
    "        str_num = str(min(nums))\n",
    "        return 1 if sum(int(digit) for digit in str_num) % 2 == 0 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        def sum_of_digits(num):\n",
    "            result = 0\n",
    "\n",
    "            while num > 0:\n",
    "                result += (num % 10)\n",
    "                num //= 10\n",
    "            return result\n",
    "        \n",
    "        min_num = min(nums)\n",
    "        return 1 if sum_of_digits(min_num) % 2 == 0 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "\n",
    "        min_value = min(nums)\n",
    "\n",
    "        s = 0\n",
    "\n",
    "        while min_value > 0:\n",
    "\n",
    "            s += min_value % 10\n",
    "\n",
    "            min_value //= 10\n",
    "        \n",
    "        \n",
    "        \n",
    "        if s % 2 == 0:\n",
    "\n",
    "            return 1\n",
    "        \n",
    "        else:\n",
    "\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfDigits(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        num = nums[0]\n",
    "        cnt = 0\n",
    "        while num:\n",
    "            cnt += num % 10\n",
    "            num //= 10\n",
    "        return 1 if cnt % 2 == 0 else 0\n",
    "              "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
